// pages/personal/personal.js
import {getUserRecord,logout} from '../../service/personal'

let startY = 0;  //手指点击起始位置
let moveY = 0; //手指移动时位置
let moveDistanceY = 0; //手指移动时的位置 - 手指点击起始位置 = 移动的距离
Page({

  /**
   * 页面的初始数据
   */
  data: {
    translateY:'translateY(0)',
    transition:'',
    profile:{},
    userRecordList:[]
  },
  // 手指点击
  touchStart(e){
    startY = e.touches[0].pageY;
    this.setData({
      transition:''
    })
  },
  // 手指移动
  touchMove(e){
    moveY = e.changedTouches[0].pageY;
    moveDistanceY = moveY - startY;
    this.setData({
      translateY:`translateY(${moveDistanceY}rpx)`
    })
  },
  // 手指松开
  touchEnd(){
    this.setData({
      translateY:'translateY(0)',
      transition:'transform .5s linear'
    })
  },
  // 跳转到登录页面
  toLogin(){
    wx.navigateTo({
      url: '/pages/login/login',
    });
  },
//退出登录
async loginout(){
  let res = await logout()
  console.log(res)
  wx.clearStorageSync("userInfo")
  wx.clearStorageSync("cookie")
  wx.reLaunch
},
toPlayList(){
  wx.navigateTo({
    url: '/pages/playList/playList',
  });
}
,
  // 请求获取用户播放列表
  async getUserRecordData(){
    // let {allData} = await getUserRecord({uid:this.data.profile.userId,type:0})
    let {data:{list}} = await getUserRecord({cookie:JSON.parse(wx.getStorageSync('cookie'))})
    console.log(list)
    this.setData({
      userRecordList:list.slice(0,10)
    })
    console.log(this.data.userRecordList);
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      profile:JSON.parse(wx.getStorageSync('userInfo'))
    })
    this.getUserRecordData()
    console.log(this.profile)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})